package com.xxb.task.xxljob;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/4/17 17:16
 */
@Slf4j
@Component
public class MyXXLJob {

    @XxlJob("myXXLJobHandler22")
    public ReturnT<String> myXXLJobHandler(String... params) throws Exception {
        // 分片的序号
        int shardIndex = XxlJobHelper.getShardIndex();
        // 分片的总数
        int shardTotal = XxlJobHelper.getShardTotal();

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        for (Integer integer : list) {
            // 相等的我再去处理我的逻辑
            if (integer % shardTotal == shardIndex) {
                log.info("MyXXLJob execute.................,shareIndex:{},shardTotal:{},{}", shardIndex, shardTotal,integer);
                XxlJobHelper.log("XXL-JOB,User createSuccess userid : " + integer + ".");
            }
        }

//        shareIndex 2  8888
//        shareIndex 0  9500
//        shareIndex 1  9800
//        1 % 3 = 1 9800
//        2 % 3 = 2 8888
//        3 % 3 = 0 9500
//        4 % 3 = 1 9800
//        5 % 3 = 2 8888
//        6 % 3 = 0 9500
//        7 % 3 = 1 9800
//        8 % 3 = 2 8888
//        9 % 3 = 0 9500
//        10 % 3 = 1  9800


        return ReturnT.SUCCESS;
    }
}
